package com.bawei.monthdemo2207a.month01.view

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonColors
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.bawei.monthdemo2207a.R
import com.bawei.monthdemo2207a.month01.route.RouteConfig

/**
 * 作者：赵亮
 * 时间：2024/12/26 11:27
 * 功能：
 */
@Composable
fun WelcomePage(navController: NavController = rememberNavController()) {

    Box(modifier = Modifier.fillMaxSize()) {
        // 欢迎页布局
        Image(
            modifier = Modifier
                .align(Alignment.Center)
                .clip(RoundedCornerShape(15.dp))
                .size(120.dp),
            painter = painterResource(id = R.drawable.logo),
            contentDescription = null
        )
        // 弹窗
        Box(
            modifier = Modifier
                .fillMaxSize()
                .background(color = colorResource(id = R.color.welcome_dialog_bg))
        ) {
            Column(
                horizontalAlignment = Alignment.CenterHorizontally,
                modifier = Modifier
                    .fillMaxWidth()
                    .align(Alignment.BottomCenter)
                    .background(
                        color = Color.White,
                        shape = RoundedCornerShape(topStart = 15.dp, topEnd = 15.dp)
                    )
            ) {
                Spacer(modifier = Modifier.height(20.dp))
                Text(text = "用户须知", fontWeight = FontWeight.Bold, fontSize = 20.sp)
                Spacer(modifier = Modifier.height(20.dp))

                // 字体大小
                val fontSize = 15.sp

                Text(
                    color = Color.Gray,
                    fontSize = fontSize,
                    text = "“软件商店”在提供服务时需要收集使用您的相关信\n" +
                            "息及以下权限:访问网络以展示在线应用内容，读\n" +
                            "写媒体影音数据以上传图片、文件，获取应用列表\n" +
                            "以提供软件更新服务，使用摄像头以提供扫描二维\n" +
                            "码功能，读取写入或删除日程表以提供预约功能，\n" +
                            "读取账号信息以获取呢称、头像等账号信息，读取\n" +
                            "剪切板信息以获取活动兑换码，读取手机识别码以"
                )
                Row {
                    Text(
                        text = "提供应用推荐服务。详情查看",
                        color = Color.Gray,
                        fontSize = fontSize
                    )
                    Text(modifier = Modifier.clickable {
                        navController.navigate(RouteConfig.XIE_YI)
                    }, text = "软件商店用户协议", color = Color.Blue, fontSize = fontSize)
                }
                Spacer(modifier = Modifier.height(20.dp))
                Button(
                    colors = ButtonDefaults.buttonColors(containerColor = Color.Green),
                    modifier = Modifier.width(180.dp),
                    onClick = {
                        // 跳转到主页面
                        navController.navigate(RouteConfig.MAIN)
                    }) {
                    Text(text = "同意并使用")
                }
                Spacer(modifier = Modifier.height(10.dp))
                Text(text = "不同意", color = Color.Green)
                Spacer(modifier = Modifier.height(20.dp))
            }
        }
    }
}

@Preview(showSystemUi = true)
@Composable
fun WelcomePagePreview() {
    WelcomePage()
}

